﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using simpleHotel.Client.UserControls;
using simpleHotel.Client.HotelReference;

namespace simpleHotel.Client.Hotel
{
    public partial class ucHotelList : BaseUserControl
    {
        public int hotelID;
        public ucHotelList()
        {
            InitializeComponent();
        }

        private void ucHotelList_Load(object sender, EventArgs e)
        {
            var service = new HotelService();
            var table = service.GetAllHotels();
            this.gvHotelList.DataSource = table;
        }

        private void panelControl1_Paint(object sender, PaintEventArgs e)
        {

        }

        

        private void butDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn xóa khách sạn?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes) {
                DeleteHotel();
            }
        }

        private void DeleteHotel()
        {
            
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            var hotelForm = new FormHotelDetail() { IsNewMode = false };

            ucHotelDetail frm = (ucHotelDetail)hotelForm.Controls[0];      
            frm.HotelId = hotelID;           
            hotelForm.ShowDialog();
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            var form = new FormHotelDetail() { IsNewMode = true };
            var dr = form.ShowDialog();
            if (dr == DialogResult.OK) { 
                //reload db
            }
        }

        private void gvHotelList_Click(object sender, EventArgs e)
        {

        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            try
            {
                DataRow row = gridView1.GetDataRow(gridView1.FocusedRowHandle);
                hotelID = int.Parse(row[0].ToString());
            }
            catch
            {
                MessageBox.Show("Error");
            }
        }
    }
}
